package com.flannery.learningandroid.learnview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import com.flannery.learningandroid.R

import kotlinx.android.synthetic.main.activity_button2.*

class ButtonActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_button2)

        initRadioButton()
        initRadioGroup()

    }

    private fun initRadioGroup() {
        rg.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.rb1 -> {
                    Toast.makeText(this@ButtonActivity, "选中第一个", Toast.LENGTH_SHORT).show()
                }
                R.id.rb2 -> {
                    Toast.makeText(this@ButtonActivity, "选中第二个", Toast.LENGTH_SHORT).show()
                }
                else -> {
                    Toast.makeText(this@ButtonActivity, "选中其他", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }

    private fun initRadioButton() {
        radioButton.setOnCheckedChangeListener { buttonView, isChecked ->
            buttonView.isChecked = isChecked
        }

    }
}
